package com.bestcem.xm.user.service.impl;

import com.bestcem.xm.user.config.properties.SettingProperties;
import com.bestcem.xm.user.constant.SmsConstant;
import com.bestcem.xm.user.constant.SystemConstant;
import com.bestcem.xm.user.grpc.client.SmsGrpcClientService;
import com.bestcem.xm.user.grpc.client.dto.SmsSendingResultDTO;
import com.bestcem.xm.user.service.UserSmsService;
import com.bestcem.xm.user.util.business.UserUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 短信相关服务
 *
 * @author panyun <yun.pan@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/11 13:43
 */
@Service
public class UserSmsServiceImpl implements UserSmsService {
    @Resource
    private SmsGrpcClientService smsGrpcClientService;

    @Resource
    private SettingProperties settingProperties;

    @Resource
    private UserUtil userUtil;

    @Override
    public Boolean sendSms(String phone, String content) {
        if (!SystemConstant.PROD_APP_ENV.equals(settingProperties.getAppEnv()) && !userUtil.checkUserIsInner(phone, null, "")) {
            return true;
        }

        String componentCode = SmsConstant.SMS_NOTIFY_COMPONENT_CODE;
        SmsSendingResultDTO sendingResult = smsGrpcClientService.sendSingleSms(phone, content, componentCode);
        return !Objects.isNull(sendingResult);
    }
}
